package chattle.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class DialogBox {
	
	protected final com.google.gwt.user.client.ui.DialogBox dlg = new com.google.gwt.user.client.ui.DialogBox(false, false); 
	protected final Panel display = new SimplePanel();
	private final Button closeButton = new Button("Close");
	
	public DialogBox(String title)
	{
		dlg.setText(title);
		dlg.setAnimationEnabled(true);
		// We can set the id of a widget by accessing its Element
		VerticalPanel dialogVPanel = new VerticalPanel();
		closeButton.getElement().setId("closeButton");
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
		dialogVPanel.add(display);
		dialogVPanel.add(closeButton);
		dlg.setWidget(dialogVPanel);

		// Add a handler to close the DialogBox
		closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				dlg.hide();
			}
		});
	}
	
	public void addCloseHandler(ClickHandler ch)
	{
		closeButton.addClickHandler(ch);
	}
	
	public Panel getDisplay()
	{
		return display;
	}
	
	public void show()
	{
		dlg.center();
		closeButton.setFocus(true);
	}
}
